<template>
  <div class="app-container">
    <!-- 输入表单 -->
    <el-form label-width="120px">
      <el-form-item label="借款额度">
        <el-input-number v-model="integralGrade.borrowAmount" :min="0" />
      </el-form-item>
      <el-form-item label="积分区间开始">
        <el-input-number v-model="integralGrade.integralStart" :min="0" />
      </el-form-item>
      <el-form-item label="积分区间结束">
        <el-input-number v-model="integralGrade.integralEnd" :min="0" />
      </el-form-item>
      <el-form-item>
        <el-button
          :disabled="saveBtnDisabled"
          type="primary"
          @click="saveOrUpdate()"
        >
          保存
        </el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
    import integralGradeApi from '@/api/core/integral_grade'

    export default {
        data(){
          return {
            integralGrade: {},
            saveBtnDisabled:false,
            id: '',
          }
        },
        created() {
          this.id = this.$route.params.id
          this.findIntegralGrade(this.id)
        },
        methods:{
          // 1. 根据id查询积分等级
          findIntegralGrade(id){
            if(id){
              integralGradeApi.getById(id).then( resp => {
                this.integralGrade = resp.data.integralGrade
              })
            }

          },
          // 2. 保存积分
          saveOrUpdate(){
            this.saveBtnDisabled = true
            if(this.id) {
                integralGradeApi.updateIntegralGrade(this.integralGrade).then(resp => {
                    this.$message.success(resp.message);
                })
            } else {
                integralGradeApi.saveIntegralGrade(this.integralGrade).then(resp => {
                    this.$message.success(resp.message);
                })
            }

            this.$router.push("/core/integral_grade/list")
          }
        },
    }
</script>

<style scoped>

</style>
